﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EnglishLibrary;
using DataTransfer;

namespace EnglishReminder
{
    public partial class AddEditNote : Form
    {
        //the object for invoking methods
        private NoteDT noteDT = new NoteDT();

        public AddEditNote()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            //the item to add
            var noteItem = new Note();

            var note = this.rtbNote.Text.Trim();
            if (note != string.Empty)
                noteItem.NoteText = note;

            var example = this.rtbExample.Text.Trim();
            if (example != string.Empty)
                noteItem.Example = example;
            //set the rateID
            noteItem.RateID = this.rateUC1.SelectedValue;
            //set the created date
            noteItem.CreatedDate = DateTime.Today;
            //set the modified date
            noteItem.ModifiedDate = DateTime.Today;

            var result = noteDT.InsertNote(noteItem);

            if (result == false)
                MessageBox.Show("Failure");
            else
                MessageBox.Show("Success");

            ClearText();
        }

        private void ClearText()
        {
            this.rtbNote.Clear();
            this.rtbExample.Clear();
        }
    }
}
